<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');

if (empty($_SESSION['uid'])) {
    $tips = array(
        'tips' => '请登录后再进行操作',
        'url' => 'index.php'
    );
    $tips = urlencode(serialize($tips));
    header('Location:/tips.php?gets=' . $tips);
    exit;
}
$user_id = $_SESSION['uid'];

$service_sn=isset($_GET["service_sn"])?$_GET["service_sn"]:"";
$repair_status=isset($_GET["repair_status"])?$_GET["repair_status"]:"";
$p=isset($_GET["p"])?$_GET["p"]:"0";
$seach_where="";
if(!empty($service_sn)){
	$seach_where.=" and service_sn='".$service_sn."'";
}
if(!empty($repair_status)){
	$seach_where.=" and status=".$repair_status;
}
if($p<1)$p=1;
$rc=$T->db->query("select count(*) from sys_takes_list where id >0 and is_delete_false = 0 and status <>7 ".$seach_where)->fetchColumn(0);

$page=getPageHtml_bt($rc,15,$p,"&t=repair_list&service_sn=".$service_sn."&repair_status=".$repair_status);
$page=mb_convert_encoding($page, 'utf-8', 'utf-8');
$status_html = "";
//$REPAIR_STATUS = ['全部','已申请','修复中','已维修','已结束','待评价','已评价','已撤回','待维修','已拒绝'];
$REPAIR_STATUS = array(
    "0"=>"全部",
    "1"=>"已申请",
    "2"=>"修复中",
    "3"=>"已维修",
    "4"=>"已结束",
    "5"=>"待评价",
    "6"=>"已评价",
	"7"=>"已撤回",
    "8"=>"待维修",
    "9"=>"已拒绝",
	"10"=>"无法处理"
);
foreach($REPAIR_STATUS as $key=>$val){
    if($key == $repair_status){
        $state = "selected";
    }else{
        $state = "";
    }
	if($key != 7){
		$status_html.="<option value='".$key."'".$state.">".$val."</option>";
	}
}
$T->Set("is_list",$rc);
$T->Set("p",$p);
$T->Set("page",$page);
$T->Set("service_sn",$service_sn);
$T->Set("status_html",$status_html);

$arr=$T->db->query("select t.*,r.id as rid,r.name as rname from sys_takes_list as t left join sys_equipment_repair as r on t.takes_type=r.id where t.id >0 and t.is_delete_false = 0 and t.status <>7 ".$seach_where." order by id desc limit ".(($p-1)*15).",15")->fetchAll();
$html='';

$REPAIR_OPT = ['','分配人员','查看详情','查看详情','查看详情','查看详情','查看详情','','查看详情','分配人员',''];
$BUTTON_COLOR = ['','layui-btn','layui-btn layui-btn-primary','layui-btn layui-btn-primary','layui-btn layui-btn-primary','layui-btn layui-btn-primary','layui-btn layui-btn-primary','','layui-btn layui-btn-primary','layui-btn',''];
foreach($arr as $v){
	$user_str=$T->db->query("select takes_user from sys_takes_list where id=".$v['id'])->fetchColumn(0);
	$user_arr=explode(",",$user_str);
	$name_arr=array();
	foreach($user_arr as $val){
		$user_name=$T->db->query("select truename from sys_member where id='".$val."'")->fetchColumn(0);
		$name_arr[]=$user_name;
	}
	$name_str=join(",",$name_arr);
	$status=$v['status'];
	$html.=<<<EOF
	<tr>
		<td>
			<input type="checkbox" name="checkbox" lay-skin="primary" value="{$v['id']}"/>
		</td>
		<td>{$v['id']}</td>
		<td>{$v['service_sn']}</td>
		<td>{$v['rname']}</td>
		<td>{$v['project_type']}</td>
		<td>{$v['code']}</td>
		<td>{$v['release_time']}</td>
		<td>{$v['takes_time']}</td>
		<td>{$name_str}</td>
		<td>{$REPAIR_STATUS[$status]}</td>
		<td>
			<button class="layui-btn-mini modal-iframe {$BUTTON_COLOR[$status]}" data-opt="update" data-status="{$status}" data-id="{$v['id']}">
				<i class="iconfont">&#xe653;</i>{$REPAIR_OPT[$status]}
			</button>
			<button class="layui-btn layui-btn-mini layui-btn-danger ajax" data-opt="del"  data-id="{$v['id']}">
				<i class="iconfont">&#xe626;</i>删除
			</button></td>
		</td>
	</tr>
EOF;
}
$T->Set("html",$html);

$T->Set("template",$template);         
$T->clearNaN();       
$T->clearNoN();
$T->display(); 